Mostly from the keyboard.
Any Java program that gets its input from the keyboard
can read its input from a file.
This is called
input redirection.
Say that you have a program
named echo.java
that writes
what the user has typed to the monitor.
Here is how the program usually works:
c:\> java echo Enter your input: User types this. You typed: User types this. c:\>
Without making any changes you can do the following:
c:\> java echo < input.txt Enter your input: You typed: This is text from the file. c:\>
The "< input.txt
" part
of the command line
connects the file input.txt
to the program and uses it as input in place of the keyboard.
In this example the file contained the characters
"This is text from the file."
The file input.txt
must exist before the program is run.
Create it using Notepad or any other text editor.